from utilities import *

from toee import *

def san_dialog( attachee, triggerer ):
	if (( game.global_flags[202] == 1 ) and ( game.quests[42].state != qs_completed )):
		triggerer.begin_dialog( attachee, 360 )
	elif (game.party[0].reputation_has( 23 ) == 1 and game.global_flags[94] == 1 and game.global_flags[851] == 0 and attachee.has_met(triggerer)): 
		triggerer.begin_dialog( attachee, 400 )
	else:
		triggerer.begin_dialog( attachee, 1 )
	return SKIP_DEFAULT

def san_first_heartbeat( attachee, triggerer ):
	if (game.global_flags[201] == 1):
		attachee.object_flag_set(OF_OFF)
		game.global_flags[202] = 0
	if not (game.global_vars[34] & 2):
		game.timevent_add(respawn, (attachee), 86400000 ) #86400000ms is 24 hours
		game.global_vars[34] | 2
	return RUN_DEFAULT

def san_dying( attachee, triggerer ):
	game.global_flags[202] = 0
	return RUN_DEFAULT

def san_resurrect( attachee, triggerer ):
	game.global_flags[202] = 1
	return RUN_DEFAULT

def prepare_goons( attachee ):
	game.timevent_add( goons_attack, ( attachee, ), 259200000 )
	return RUN_DEFAULT	

def goons_attack( attachee ):
	if game.quests[42].state != qs_completed:
		game.quests[42].state = qs_botched
		game.global_flags[202] = 1
		game.encounter_queue.append(3004)
	return RUN_DEFAULT

def respawn(attachee):
	for box in game.obj_list_vicinity( attachee.location, OLC_CONTAINER ): 
		if box.name == 1001 and box.obj_get_int(obj_f_container_inventory_source) == 15:
			RespawnInventory(box)
			game.timevent_add(respawn, (attachee), 86400000 ) #86400000ms is 24 hours
	return
